﻿using System;
using CommonDomain;
using Sponsorship.Domain.Sponsors;

namespace Sponsorship.Domain.Sponsorships
{
    /// <summary>
    /// Represents a sponsorship in the Sponsorship domain. A <see cref="Sponsorship"/> can be associated with a <see cref="Sponsor"/>.
    /// </summary>
    public class Sponsorship : RelaxedAggregateBase
    {
        public Sponsorship (Guid id, Guid sponsorshipTypeId, Guid personId, Guid sponsorId, decimal amount, DateTime? startDate, DateTime? enddate, Period period, string comment)
            : this (id, null)
        {
            if (id == Guid.Empty)
                throw new ArgumentException ("Id must not be empty.", "id");

            RaiseEvent (new SponsorshipEntered (id, sponsorshipTypeId, personId, sponsorId, amount, startDate, enddate, period, comment));
        }

        // Infrastructure constructor used by AggregateFactory
        private Sponsorship (Guid id, IMemento snapshot)
        {
            if (snapshot != null)
                throw new NotSupportedException ("This class does not support snapshots.");
            Id = id;
        }

        public void Delete()
        {
            RaiseEvent (new SponsorshipDeleted (Id));
        }

        internal void Change (Guid sponsorshipTypeId, Guid personId, Guid sponsorId, decimal amount, DateTime? startDate, DateTime? endDate, Period period, string comment)
        {
            RaiseEvent (new SponsorshipChanged (Id, sponsorshipTypeId, personId, sponsorId, amount, startDate, endDate, period, comment));
        }

        protected override IMemento GetSnapshot()
        {
            throw new NotSupportedException ("This class does not support snapshots.");
        }
    }
}